import React,{Component} from 'react'
import { Card, Row ,Col} from 'antd'
import Profit from './components/Profit'
import RecentSevenDays from './components/RecentSevenDays'
import VarietyOfDishes from './components/VarietyOfDishes'
import { connect } from 'react-redux';
import * as actions from './store/action';
import * as actions2 from '@pages/Home/store/action';

class DatStatistics extends Component{
    componentDidMount() {
        const obj = {
            method: "loginRequest",
            api: "/web/rest/user/isLogin",
            cmd: "isLogin",
            request: {},
        };
        this.props.get_islogin(obj);
        if (this.props.isLogin == false) {
            window.location.href = '/login'
        }
        this.props.getAllDatStatisticsRequest(1)


    }
        render(){
            const { ordersInRecentSevenDays, menuList}=this.props;
            return(
                <Card
                    title="数据统计"
                    bordered={false}
                >
                    <Row >
                        <Col span={24} >
                            <Profit 
                                menuList={menuList}
                            />
                        </Col>
                        <Col span={12}>
                            < RecentSevenDays
                                ordersInRecentSevenDays={ordersInRecentSevenDays}
                            />
                        </Col>
                        <Col span={12}>
                            <VarietyOfDishes
                                ordersInRecentSevenDays={ordersInRecentSevenDays}
                            />
                        </Col>
                    </Row>
                </Card>
            )
        }
}
const mapStateToProps = (state) => ({
    menuList: state.getAllBoardDatas.menuList,
    // 获取所数据
    ordersInRecentSevenDays: state.getAllBoardDatas.ordersInRecentSevenDays,
})

const mapDispatchToProps = dispatch => ({
    // 获取所有数据
    getAllDatStatisticsRequest(id) {
        dispatch(actions.getAllDatStatisticsRequest(id))
    },
    get_islogin() {
        dispatch(actions2.isloginRequest());
    },
})
export default connect(mapStateToProps, mapDispatchToProps)(DatStatistics);
